﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace _47文件流复制文件
{
    class Program
    {
        static void Main(string[] args)
        {
            CopyFile(@"E:\U\text.txt", @"E:\text.txt");
        }
        static void CopyFile(string file, string targetDir)
        {
            //创建文件流
            string fileName = Path.GetFileName(file);
            string targetFile = Path.Combine(targetDir, file);
            using (FileStream fsRead = File.OpenRead(file), fsWrite = File.Create(targetDir))
            {
                //读取
                byte[] array = new byte[1024 * 1024 * 20];
                while (true)
                {
                    int length = fsRead.Read(array, 0, array.Length);
                    if (length == 0)
                        break;
                    fsWrite.Write(array, 0, length);
                }
                fsWrite.Flush();
            }

        }
    }
}
